"""
报表关键字
"""
import pytest
from Config.Base import Base
from playwright.sync_api import Page, expect, Playwright
from Config.config import *
from Config.URL import *
import allure, os
from Config.Base import Base
from Config.Tool import tool


@pytest.mark.基础管理系统
@pytest.mark.系统管理
def test_case(playwright : Playwright) -> None:

    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    page.goto(url+url_login)
    page.get_by_placeholder("请输入用户名").fill(username_admin)
    page.get_by_placeholder("请输入密码").fill(password_admin)
    page.get_by_role("button", name="登 录").click()
    page.get_by_text("UAT-环北部湾广西水资源配置工程").first.click()
    page.wait_for_timeout(1000)
    page.goto(url+url_baobiaoguanjianzi)
    page.get_by_role("button", name=" 新建").click()
    page.get_by_placeholder("请选择分类").click()
    page.get_by_title("施工管理报表").click()
    page.get_by_label("新建").get_by_placeholder("请输入名称").fill("AutoTest-关键字")
    page.get_by_placeholder("请输入关键字").fill("{{CONTRACTNUMBER}}")
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("paragraph")).to_contain_text("新建成功！")


    # 测试结果截图
    filename = os.path.join(test_screenshot_dir, f"{'AutoTest-关键字'}.png")
    page.screenshot(path=filename)
    allure.attach.file(source=filename, name="AutoTest-关键字",
                       attachment_type=allure.attachment_type.PNG)

    page.get_by_role("textbox", name="请输入名称", exact=True).fill("AutoTest-关键字")
    page.get_by_role("button", name=" 查询").click()
    # 获取tbody下面元素tr个数
    expect(page.locator("tbody > tr")).to_have_count(1)
    # 获取是否存在文本text
    expect(page.locator("tbody")).to_contain_text("AutoTest-关键字")
    page.get_by_role("button", name="删除").click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_text('删除成功！')).to_be_visible()


    SetupTeardown.close()
